package com.macrounion.atv.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Tag;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger {
	
	@Value("${swagger.enable:false}")
	private boolean enableSwagger;
	
	@Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(enableSwagger)
                /* .tags 第一个参数必须是Tag，后面的是 Tag 类型的可选参数
                 new Tag(String,String) 第一个参数是key，第二个参数是Value。注解@Api#tags传入的是tag的key */
                .tags(new Tag("user", "用户相关API"),getTags())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.macrounion.atv.controller.api"))
                .paths(PathSelectors.any())
                .build();
    }

    private Tag[] getTags() {
        Tag[] tags = {
//            new Tag("paylink","相关")
        };
        return tags;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("相关API")
                .description("api根地址：http://127.0.0.1/82")
//                .termsOfServiceUrl("https://xiaomo.info/")
//                .contact(new Contact("张超","",""))
                .version("1.0")
                .build();
    }
}
